﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Twitterizer;

namespace TwiMixer.RESTAPI.Twitter
{
    public class TwitterRESTAPI :APIProvider
    {
        public TwitterRESTAPI(OAuthTokens token, string callbackUrl)
        {
            RequestTokenUrl = " https://api.twitter.com/oauth/request_token";
            AuthorizeBaseUrl = " https://api.twitter.com/oauth/";
            AccessTokenUrl = " https://api.twitter.com/oauth/access_token";
            ConsumerKey = token.ConsumerKey;
            ConsumerSecret = token.ConsumerSecret;
            CallbackUrl = callbackUrl;

            ApiProviderType = APIProviderEnum.tweet;
            
        }


        public override string GetOAuthAuthorizationUrl()
        {
            OAuthTokenResponse response = OAuthUtility.GetRequestToken(
                                                new Uri(RequestTokenUrl),
                                                ConsumerKey,
                                                ConsumerSecret,
                                                CallbackUrl);

            HttpContext context = HttpContext.Current;
            context.Response.Cookies[response.Token].Value = response.TokenSecret;

            Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(AuthorizeBaseUrl, response.Token, false);

            

            return authorizationUri.ToString();
        }

        public override OAuthTokenResponse GetOAuthToken(string requestToken, string verifier, string requestTokenSecret)
        {
            OAuthTokenResponse response =
                OAuthUtility.GetAccessTokenDuringCallback(AccessTokenUrl, ConsumerKey, ConsumerSecret, requestTokenSecret);

            return response;
        }

        public override string GetStatusesHomeTimeline(int count, int since_id, int max_id, int page, bool trim_user, bool include_rts, bool include_entities, bool exclude_replies, bool contributor_details)
        {
            throw new NotImplementedException();
        }

        public override string GetStatusesHomeTimeline()
        {
            throw new NotImplementedException();
        }
    }
}